import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

/**
 * 
 */

/**
 * @author melike
 * 
 */
public class Test {

	public static void main(String[] args) {
		try {

			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc = dBuilder.parse("http://www.omdbapi.com/?t=The%20Matrix&r=XML&tomatoes=true");

			// optional, but recommended
			// read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
			doc.getDocumentElement().normalize();

			System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

			/*
			 * <imdbid>tt0133093</imdbid> <imdburl>http://www.imdb.com/title/tt0133093/</imdburl> <genres>Action,Adventure,Sci-Fi</genres> <languages>English</languages> <country>USA,Australia</country> <votes>723415</votes> <stv>0</stv>
			 * <series>0</series> <rating>8.7</rating> <runtime>136min</runtime> <title>The Matrix</title> <year>1999</year> <usascreens>2903</usascreens> <ukscreens>366</ukscreens> <cacheExpiry>1375140759</cacheExpiry>
			 */
			String imdbid = doc.getElementsByTagName("movie").item(0).getTextContent();
			System.out.println(imdbid);

			/*
			 * NodeList nList = doc.getElementsByTagName("staff");
			 * 
			 * System.out.println("----------------------------");
			 * 
			 * for (int temp = 0; temp < nList.getLength(); temp++) {
			 * 
			 * Node nNode = nList.item(temp);
			 * 
			 * System.out.println("\nCurrent Element :" + nNode.getNodeName());
			 * 
			 * if (nNode.getNodeType() == Node.ELEMENT_NODE) {
			 * 
			 * Element eElement = (Element) nNode;
			 * 
			 * System.out.println("Staff id : " + eElement.getAttribute("id")); System.out.println("First Name : " + eElement.getElementsByTagName("firstname").item(0).getTextContent()); System.out.println("Last Name : " +
			 * eElement.getElementsByTagName("lastname").item(0).getTextContent()); System.out.println("Nick Name : " + eElement.getElementsByTagName("nickname").item(0).getTextContent()); System.out.println("Salary : " +
			 * eElement.getElementsByTagName("salary").item(0).getTextContent());
			 * 
			 * } }
			 */
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
